(function () {
    window.FrameUtil = class FrameUtil {
        constructor (fps) {
            // 当前帧号
            this.currentFrame = 0
            // 开始统计时间和开始帧
            this.stateFrame = 0
            this.startTime = new Date()
            this.realFps = fps
        }
        update() {
            this.currentFrame++
            const now = new Date()
            if (now - this.startTime >= 1000) {
                this.realFps = this.currentFrame - this.stateFrame
                this.startTime = now
                this.stateFrame = this.currentFrame
            }
        }
        render () {
            game.context.font='20px 黑体'
            game.context.fillText(`fps:${this.realFps}`, 0,15)
        }
    }
})()